package uestc.lj.basic.listnode;

/**
 * 找出两个有序链表中的公共部分
 *
 * @Author:Crazlee
 * @Date:2021/11/22
 */
public class Code02_findCommonNode {
	public static class Node {
		public int value;
		public Node next;

		public Node(int data) {
			this.value = data;
		}
	}

	public static void findCommonNode(Node head1, Node head2) {
		System.out.println("两个链表的公共节点是：");
		while (head1 != null && head2 != null) {
			if (head1.value < head2.value) {
				head1 = head1.next;
			} else if (head1.value > head2.value) {
				head2 = head2.next;
			} else {
				System.out.print(head1.value + " ");
				head1 = head1.next;
				head2 = head2.next;
			}
		}
	}
}
